package com.ning.memoryleak.activity;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.ning.memoryleak.R;
import com.ning.memoryleak.app.App;
import com.squareup.leakcanary.RefWatcher;

/**
 * @作者: njb
 * @时间: 2019/11/20 13:12
 * @描述: 线程引起的内存泄露
 */
public class LeakThreadActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_leak_therad);
        initThread();
    }

    private void initThread() {
        LeakThread leakThread = new LeakThread();
        leakThread.start();
    }

     static class LeakThread extends Thread {
        @Override
        public void run() {
            try {
                Thread.sleep(6 * 60 * 1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        RefWatcher refWatcher = App.getRefWatcher(this);
        refWatcher.watch(this);
    }
}
